package org.ricks.log;

/**
 * @author chenwei
 * @Title:
 * @Package
 * @Description:
 * @date 2021/1/2917:46
 */
public interface FileConverter {

    /**
     * Gets the additional file extension for backup files.
     *
     * <p>
     *     The method can return {@code null}, if this converter does not create backup files with different file
     *     extensions.
     * </p>
     *
     * @return Additional file extension or {@code null}
     */
    String getBackupSuffix();

    /**
     * This method is called when tinylog opens a log file for writing log entries.
     *
     * @param fileName
     *            Log file
     */
    void open(String fileName);

    /**
     * This method can convert data before writing to the currently opened log file.
     *
     * @param data
     *            Data to write to the currently opened log file
     * @return The passed byte array or a new byte array that should be written instead
     */
    byte[] write(byte[] data);

    /**
     * This method is called when tinylog closes the current log file.
     */
    void close();

    /**
     * Shuts this file converter down.
     *
     * <p>
     *     If the converter has started any further threads, this method must await their termination.
     * </p>
     *
     * @throws InterruptedException
     *             Interrupted while waiting
     */
    void shutdown() throws InterruptedException;

}